//
//  ByMyDocumentaryDetailCell.m
//  caipiao_ios
//
//  Created by mc on 2018/8/24.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByMyDocumentaryDetailCell.h"
#import "ByDocumentaryFiveValue.h"



@implementation ByMyDocumentaryDetailCell

+ (instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString *cellIdentifier = @"ByMyDocumentaryDetailCell";
    ByMyDocumentaryDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        self.contentView.backgroundColor = BY_BACKGROUND_COLOR;
        
    }
    return self;
}


- (void)initViews{
    
    [self.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    
    UIView *backgroundView = [[UIView alloc] init];
    [self.contentView addSubview:backgroundView];
    [backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(0);
        make.right.equalTo(self.contentView).offset(0);
        make.bottom.equalTo(self.contentView).offset(-5);
        make.top.equalTo(self.contentView).offset(2);
    }];
    backgroundView.backgroundColor = [UIColor whiteColor];
    backgroundView.layer.cornerRadius = 5;
    
    UILabel *titleLabel = [[UILabel alloc] init];
    [backgroundView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(15);
        make.top.equalTo(backgroundView).offset(15);
        make.height.mas_equalTo(@15);
        make.width.mas_equalTo(@60);
    }];
    titleLabel.font = FONT(13);
    titleLabel.textColor = BY_TEXT_COLOR;
    titleLabel.text = @"方案详情";
    
    UILabel *leftLabel = [[UILabel alloc] init];
    [backgroundView addSubview:leftLabel];
    [leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLabel.mas_right).offset(15);
        make.top.equalTo(backgroundView).offset(10);
        make.size.mas_equalTo(CGSizeMake(40, 25));
    }];
    leftLabel.backgroundColor = rgba(248, 116, 123, 1);
    leftLabel.textColor = [UIColor whiteColor];
    leftLabel.text = @"2场";
    leftLabel.font = FONT(12);
    leftLabel.textAlignment = NSTextAlignmentCenter;
    
    CGFloat center_width = [[ByFootBallHandle getFootBallFreePassStringWithString:_netModel.free_pass] getRectOfStringWithSize:CGSizeMake(1000, 20) font:12].size.width + 10;
    UILabel *centerLabel = [[UILabel alloc] init];
    [backgroundView addSubview:centerLabel];
    [centerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(leftLabel.mas_right).offset(15);
        make.top.equalTo(backgroundView).offset(10);
        make.size.mas_equalTo(CGSizeMake(center_width, 25));
    }];
    centerLabel.backgroundColor = rgba(246, 210, 44, 1);
    centerLabel.textColor = [UIColor whiteColor];
    centerLabel.text = @"2串1";
    centerLabel.font = FONT(12);
    centerLabel.textAlignment = NSTextAlignmentCenter;
    
    UILabel *rightLabel = [[UILabel alloc] init];
    [backgroundView addSubview:rightLabel];
    [rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(centerLabel.mas_right).offset(15);
        make.top.equalTo(backgroundView).offset(10);
        make.size.mas_equalTo(CGSizeMake(60, 25));
    }];
    rightLabel.backgroundColor = rgba(50, 218, 168, 1);
    rightLabel.textColor = [UIColor whiteColor];
    rightLabel.text = @"1548倍";
    rightLabel.font = FONT(12);
    rightLabel.textAlignment = NSTextAlignmentCenter;
    
    UIImageView *stateView = [[UIImageView alloc] init];
    [backgroundView addSubview:stateView];
    [stateView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(backgroundView).offset(-19);
        make.centerY.equalTo(rightLabel.mas_centerY).offset(0);
        make.size.mas_equalTo(CGSizeMake(40, 21));
    }];
    if (_netModel.ticket_status.integerValue == -1) {
        stateView.image = [UIImage imageNamed:@"yiguoqi已过期"];
    }else if (_netModel.ticket_status.integerValue == 0){
        stateView.image = [UIImage imageNamed:@"weichupiao未出票"];
    }else if (_netModel.ticket_status.integerValue == 1){
        stateView.image = [UIImage imageNamed:@"chupiaozhong出票中"];
    }else if (_netModel.ticket_status.integerValue == 2){
        stateView.image = [UIImage imageNamed:@"chupiaochenggong出票成功"];
    }else if (_netModel.ticket_status.integerValue == 3){
        stateView.image = [UIImage imageNamed:@"chupiaoshibai出票失败"];
    }
    
    
    
    UIView *grayView = [[UIView alloc] init];
    [backgroundView addSubview:grayView];
    grayView.backgroundColor = rgba(255, 248, 249, 1);
    grayView.layer.borderColor = BY_LINE_COLOR.CGColor;
    grayView.layer.borderWidth = 1;
    [grayView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(18);
        make.right.equalTo(backgroundView).offset(-18);
        make.top.equalTo(backgroundView).offset(44);
        make.bottom.equalTo(backgroundView).offset(-12);
    }];
    
    self.leftLabel = leftLabel;
    self.centerLabel = centerLabel;
    self.rightLabel = rightLabel;
    
    CGFloat width = SCREEN_WIDTH - 36;
    ByDocumentaryFiveValue *titleView = [[ByDocumentaryFiveValue alloc] initWithFrame:CGRectMake(0, 0, width, 35)];
    [grayView addSubview:titleView];
    titleView.valueLabel1.text = @"场次";
    titleView.valueLabel2.text = @"主队";
    titleView.valueLabel3.text = @"投注方案";
    titleView.valueLabel4.text = @"客队";
    titleView.valueLabel5.text = @"开奖结果";
    NSArray *dataArray = _netModel.ball_infoArray;
    CGFloat top = 35;
    for (int i = 0; i < dataArray.count; i++) {
        ByNetModel *netModel = [dataArray objectAtIndex:i];
        ByDocumentaryFiveValue *valueView = [[ByDocumentaryFiveValue alloc] initWithFrame:CGRectMake(0, top, width, Documentary_Table_Height)];
        [grayView addSubview:valueView];
        top = top + Documentary_Table_Height;
        valueView.valueLabel1.text = [NSString stringWithFormat:@"%@",netModel.num];
        valueView.valueLabel2.text = [NSString stringWithFormat:@"%@",netModel.h_cn];
        
        if (_isMyDocumentary) {
            valueView.valueLabel3.text = netModel.planDic[netModel.p_time];
        }else{
            
            if (netModel.public_type.integerValue == 2) {
                valueView.valueLabel3.text = netModel.planDic[netModel.p_time];
            }else if (netModel.public_type.integerValue == 1 && netModel.is_result.integerValue == 1){
                 valueView.valueLabel3.text = netModel.planDic[netModel.p_time];
            }else{
                valueView.valueLabel3.text = @"";
            }
        }
        
        
        valueView.valueLabel4.text = netModel.a_cn;
        if (netModel.is_result.integerValue == 0) {
            valueView.valueLabel5.text = @"未开奖";
        }else{
            valueView.valueLabel5.text = netModel.final_score;
            if (_netModel.lottery_type.integerValue == 2) {
                valueView.valueLabel5.text = netModel.game_Result; 
            }
        }
        
        valueView.valueLabel1.textColor = [UIColor colorWithHexString:@"#666666"];
        valueView.valueLabel2.textColor = [UIColor colorWithHexString:@"#666666"];
        valueView.valueLabel3.textColor = [UIColor colorWithHexString:@"#666666"];
        valueView.valueLabel4.textColor = [UIColor colorWithHexString:@"#666666"];
        valueView.valueLabel5.textColor = [UIColor colorWithHexString:@"#666666"];
    }
    
    for (int i = 0; i< dataArray.count + 1; i++) {
        UILabel *centerLine = [[UILabel alloc] init];
        [grayView addSubview:centerLine];
        centerLine.backgroundColor = BY_LINE_COLOR;
        if (i == dataArray.count) {
            [centerLine mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(grayView).offset(0);
                make.right.equalTo(grayView).offset(0);
                make.top.equalTo(grayView).offset(35);
                make.height.mas_equalTo(@1);
            }];
        }else{
            [centerLine mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(grayView).offset(0);
                make.right.equalTo(grayView).offset(0);
                make.bottom.equalTo(grayView).offset(-Documentary_Table_Height * i);
                make.height.mas_equalTo(@1);
            }];
        }
        
    }
    
    
    
    for (int i = 1; i < 5; i++) {
        UILabel *line = [[UILabel alloc] init];
        [grayView addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(grayView).offset(width / 5.0 * i);
            make.bottom.equalTo(grayView).offset(0);
            make.top.equalTo(grayView).offset(0);
            make.width.mas_equalTo(@1);
        }];
        line.backgroundColor = BY_LINE_COLOR;
    }
    

}

- (void)setIsMyDocumentary:(BOOL)isMyDocumentary{
    _isMyDocumentary = isMyDocumentary;
}

- (void)setNetModel:(ByNetModel *)netModel{
    _netModel = netModel;
    [self initViews];
    self.leftLabel.text = [NSString stringWithFormat:@"%ld场", _netModel.ball_infoArray.count];
    self.centerLabel.text = [ByFootBallHandle getFootBallFreePassStringWithString:_netModel.free_pass];
    self.rightLabel.text = [NSString stringWithFormat:@"%@倍", netModel.multiple];
    
    
    
    
}

@end
